<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<html>
<head>

    <script type="text/javascript">
        var detailsInfoUrl = "companydetails/detailsInfo.do";
        $(document).ready(function () {
            $('#details-fm').form('syncLoad', detailsInfoUrl);
            $("#imageurlx").attr("src", basePath + $('#photoPath').val());
            CKEDITOR.replace("content");//重新实例化富文本
        });
        $("#submit_upload_identificationPhoto").click(function () {
            var filename = $("#advertisementPic").val();
            var extStart = filename.lastIndexOf(".");
            var ext = filename.substring(extStart, filename.length).toUpperCase();
            if (ext != ".BMP" && ext != ".PNG" && ext != ".GIF" && ext != ".JPG" && ext != ".JPEG") {
                $messager.alert("操作提示", "图片限于bmp,png,gif,jpeg,jpg格式", "error");
                return;
            }
            $.ajaxFileUpload({
                url: 'rest/uploadToFastDFS.do',
                secureuri: false,
                fileElementId: 'advertisementPic',
                data: null,
                dataType: 'text',
                success: function (data, status) {
                    data = data.replace("<PRE>", '');  //ajaxFileUpload会对服务器响应回来的text内容加上<pre>text</pre>前后缀
                    data = data.replace("</PRE>", '');
                    data = data.replace("<pre>", '');
                    data = data.replace("</pre>", '');
                    var obj = eval("(" + data + ")");
                    if (obj.states == "0") {
                        $('#imageidx').val(obj.ImageId);
                        $('#photoPath').val(obj.imgUri);
                        $("#imageurlx").attr("src", basePath + obj.imgUri);
                        $("#imgx").show();
                    } else {
                        alert(obj.msg);
                    }
                },
                error: function (data, status, e) {
                    alert("上传失败");
                }
            });
        });
        function editdDetails() {
            $('#details-fm').form('submit', {
                url: 'companydetails/editDetails.do',
                onSubmit: function () {
                    var validator = $(this).form('validate');
                    if (validator) {
                        $.messager.progress();
                    }
                    return validator;
                },
                success: function (result) {
                    $.messager.progress('close');
                    var result = eval('(' + result + ')');
                    if (result.retCode == '0000') {
                        back("companydetails/index.do");
                    } else {
                        $.messager.show({
                            title: 'Error',
                            msg: result.retMsg
                        });
                    }
                }
            });
        }
        function back(url) {
            $.get(url, {}, function (data) {
                $("#center").empty();
                $("#center").html(data);
                $.parser.parse($("#center"));
            });
        }
    </script>
</head>
<body>
<div class="linkbar"><a>公司详情管理</a>/<a>编辑公司详情</a></div>
<div id="details-add">
    <form id="details-fm" method="post" novalidate>
        <br>
        <br>
        <br>
        <div class="fitem">
            <label>详情标题：</label> <input name="title"
                                        style="width:200px;"
                                        class="easyui-validatebox" missingMessage="该输入项不能为空！"
                                        required="true"/>
        </div>
        <br>
        <div class="fitem">
            <label>图片:</label>
            <input type="file" id="advertisementPic" name="photo"
                   missingMessage="该输入项不能为空！" style="width:200px;"
                   required="true"/>
            <a class="easyui-linkbutton" id="submit_upload_identificationPhoto">上传图片</a>
            <font color="red">*请先上传图片，再进行保存</font>
        </div>

        <div id="imgx" class="shangc_nav clearfix">
            <img id="imageurlx" src="" style="width:100px;"/>
            <input type="hidden" name="photoPath" id="photoPath" class="easyui-validatebox" missingMessage="该输入项不能为空！"
                   required="true"/>
        </div>
        <br>
        <div class="fitem">
            <label>内容：</label>
            <textarea id="content"  name="content"
                      class="ckeditor"  style="width:800px;height:800px;" />
        </div>
    </form>
</div>
<br>
</form>
<div id="dlg-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok"
       onclick="editdDetails()">保存</a> <a href="#" class="easyui-linkbutton"
                                          iconCls="icon-cancel" onclick="back('companydetails/index.do')">返回</a>
</div>
</div>
</body>
</html>